package bravo.xc.com.xc_bravo_android.operation.order;

import android.util.Log;

import bravo.xc.com.xc_bravo_android.beans.MessageBeans;
import bravo.xc.com.xc_bravo_android.beans.MessageResultBeans;
import bravo.xc.com.xc_bravo_android.http.HttpSingleton;
import bravo.xc.com.xc_bravo_android.http.UserOperationService;
import rx.Subscriber;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

/**
 * CREATED BY YANK
 * DATE : 2017/11/5
 * MAIL : YANK.TENYOND@GMAIL.COM
 * FUNCTION :
 */

public class OrderPresenter extends OrderContract.OrderPresenter{

    private UserOperationService userOperationService;

    @Override
    public void doGetMessage(MessageBeans messageBeans) {

        userOperationService = HttpSingleton.getInstance().service;
        compositeSubscription.add(userOperationService.getMessage(messageBeans)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Subscriber<MessageResultBeans>() {
                    @Override
                    public void onCompleted() {

                    }

                    @Override
                    public void onError(Throwable e) {
                        Log.e("@@onError",String.valueOf(e));
                        view.showToast("网络错误，请重试");
                    }

                    @Override
                    public void onNext(MessageResultBeans messageResultBeans) {
                        if(messageResultBeans.getCode() == 1){
                            view.setAdapter(messageResultBeans);
                        }else {
                            view.showToast("出现未知错误");
                        }
                    }
                }));

    }

}
